package com.xnew.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.xnewtech.xplatform.swan.model.page.PageResult;
import com.xnewtech.xplatform.swan.model.web.response.ResponseData;
import com.xnew.model.params.SysConfigParam;
import com.xnew.model.result.SysConfigResult;
import com.xnew.service.SysConfigService;
import com.xnewtech.xplatform.swan.libs.scanner.annotation.PostResource;
import com.xnewtech.xplatform.swan.libs.scanner.stereotype.ApiResource;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 参数配置控制器
 *
 * @author shj
 * @Date 2021-08-09 15:49:46
 */
@RestController
@ApiResource(name = "参数配置管理", path = "/sysConfig")
public class SysConfigController {


    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 新增
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "添加", path = "/add")
    public ResponseData add(@RequestBody SysConfigParam param) {
        sysConfigService.add(param);
        return ResponseData.success();
    }

    /**
     * 修改
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "修改", path = "/update")
    public ResponseData update(@RequestBody SysConfigParam param) {
        sysConfigService.update(param);
        return ResponseData.success();
    }

    /**
     * 删除
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "删除", path = "/delete")
    public ResponseData delete(@RequestBody SysConfigParam param) {
        sysConfigService.delete(param);
        return ResponseData.success();
    }

    /**
     * 查询单条详情
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "查询详情", path = "/queryDetail")
    public ResponseData queryDetail(@RequestBody SysConfigParam param) {
        SysConfigResult result = sysConfigService.findBySpec(param);
        return ResponseData.success(result);
    }

    /**
     * 查询列表
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "查询列表", path = "/queryList")
    public ResponseData queryList(@RequestBody SysConfigParam param) {
        List<SysConfigResult> listBySpec = sysConfigService.findListBySpec(param);
        return ResponseData.success(listBySpec);
    }

    /**
     * 分页查询列表
     *
     * @author shj
     * @Date 2021-08-09
     */
    @PostResource(name = "分页查询列表", path = "/queryListPage")
    public ResponseData queryListPage(@RequestBody SysConfigParam param) {
        PageResult<SysConfigResult> pageBySpec = sysConfigService.findPageBySpec(param);
        return ResponseData.success(pageBySpec);
    }

}
